<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

	</head>

	<body>
		<div class="page-content-wrap">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-inline tool-btn">
							<button class="layui-btn layui-btn-small layui-btn-normal addBtn hidden-xs" data-url="../index/user-add.jsp"><i class="layui-icon">&#xe654;</i></button>
							<%--<button class="layui-btn layui-btn-small layui-btn-warm listOrderBtn hidden-xs" data-url="/admin/category/listorderall.html"><i class="iconfont">&#xe656;</i></button>--%>
						</div>


					</div>
				</form>
				<div class="layui-form" id="table-list">
					<table class="layui-table" lay-even lay-skin="nob">
						<colgroup>
							<col width="50">
							<col class="hidden-xs" width="50">
							<col class="hidden-xs" width="100">
							<col>
							<col width="80">
							<col width="150">
						</colgroup>
						<thead>
							<tr class="title">
								<th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
								<th >ID</th>
								<th >部门</th>
								<th >真实姓名</th>
								<th >用户名</th>
								<th >角色</th>
								<th >电话</th>
								<th >工资</th>
								<th>操作</th>

							</tr>
						</thead>
						<tbody>
							<%--<tr>
								<td><input type="checkbox" name="" lay-skin="primary" ></td>
								<td class="deptName">1</td>
								<td class="deptTel"></td>
								<td class="deptEmail">首页</td>
								<td class="deptAddress"><td>
									<div class="layui-inline">
										<button class="layui-btn layui-btn-mini layui-btn-normal  add-btn"  data-url="menu-add2.html"><i class="layui-icon">&#xe654;</i></button>
										<button class="layui-btn layui-btn-mini layui-btn-normal  edit-btn"  data-url="menu-add2.html"><i class="layui-icon">&#xe642;</i></button>
										<button class="layui-btn layui-btn-mini layui-btn-danger del-btn"  data-url="del.html"><i class="layui-icon">&#xe640;</i></button>
									</div>

								</td>
							</tr>--%>

						</tbody>
					</table>



				</div>
		</div>
		<script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
		<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
		<script>
			$(document).ready(function(){
				showaccountAjax();
			})

			function showaccountAjax(){
				//渲染用户信息
				$.ajax({
					async:true,
					url:"${pageContext.request.contextPath}/account/getAccountByPage",
					type:"POST",
					data:{
						pageNum:"1",
						pageSize:"20"
					},
					dataType:"json",
					success:function(result,status,xhr){
						$.each(result.list,function(index,account){
							$("tbody").append("<tr>\n" +
									"\t\t\t\t\t\t\t\t<td><input type=\"checkbox\" name=\"\" lay-skin=\"primary\" ></td>\n" +
									"\t\t\t\t\t\t\t\t<td class=\"accountId\">"+account.accountId+"</td>\n" +
									"\t\t\t\t\t\t\t\t<td class=\"deptName\">"+account.deptName+"</td>\n" +
							"\t\t\t\t\t\t\t\t<td class=\"realName\">"+account.realName+"</td>\n" +
							"\t\t\t\t\t\t\t\t<td class=\"accountName\">"+account.accountName+"</td>\n" +
							"\t\t\t\t\t\t\t\t<td class=\"roleName\">"+account.roleName+"</td>\n" +
							"\t\t\t\t\t\t\t\t<td class=\"accountTel\">"+account.accountTel+"</td>\n" +
							"\t\t\t\t\t\t\t\t<td class=\"salary\">"+account.salary+"<td>\n" +
							"\t\t\t\t\t\t\t\t\t<div class=\"layui-inline\">\n" +
							"\t\t\t\t\t\t\t\t\t\t<button class=\"layui-btn layui-btn-mini layui-btn-normal  edit-btn\"  data-url='../index/user-update.jsp?accountId="+account.accountId+"'><i class=\"layui-icon\">&#xe642;</i></button>\n" +
									"\t\t\t\t\t\t\t\t<a  href='#'  class=\"deleteBtn\"  style='color:red'>删除</a>\n" +
							"\t\t\t\t\t\t\t\t\t</div>\n" +
							"\t\t\t\t\t\t\t</tr>")
						});


					},
					error:function(xhr,status,error){
						alert("异步请求失败!");
					}
				});

			}
			//删除按钮
			$(document).on("click",".deleteBtn",function(){
				var accountId = $(this).parents("tr").children("td.accountId").text();

				$.ajax({
					async:true,
					url:"${pageContext.request.contextPath}/account/deleteAccountInfo",
					type:"get",
					data:{
						accountId:accountId
					},
					dataType:"json",
					success:function(result,status,xhr){

						if(result == "1"){
							alert("删除成功");
							$("tr").not(".title").remove();
						}else {
							alert("删除失败");
						}
						showaccountAjax();
					},
					error:function(xhr,status,error){
						alert("异步请求失败!");
					}
				})
			})


			$(document).on("click",".layui-layer-close",function(){
				$("tr").not(".title").remove();
				showaccountAjax();
			})















		</script>
	</body>

</html>